import { request, API_BASE_URL } from '@/utils/http';

// OA审批统计相关接口

// 查询待处理
export const queryPendingApi = async () => {
  return await request(`${API_BASE_URL}/OA/query/pending`, {
    method: 'POST',
    data: {},
  });
};

// 查询已处理
export const queryProcessedApi = async () => {
  return await request(`${API_BASE_URL}/OA/query/processed`, {
    method: 'POST',
    data: {},
  });
};

// 查询已发起
export const queryInitiatedApi = async () => {
  return await request(`${API_BASE_URL}/OA/query/initiated`, {
    method: 'POST',
    data: {},
  });
};

// 查询已收到
export const queryReceivedApi = async () => {
  return await request(`${API_BASE_URL}/OA/query/received`, {
    method: 'POST',
    data: {},
  });
};

// 审核合同 - 使用string类型避免长整数精度丢失
export const dealContractApi = async (id: string, agree: boolean,remark:string) => {
  return await request(`${API_BASE_URL}/OA/contract/dealContract`, {
    method: 'POST',
    data: {
      id,
      agree,
      remark,
    },
  });
};

// 审核报销 - 使用string类型避免长整数精度丢失
export const dealBaoXiaoApi = async (id: string, agree: boolean,remark:string) => {
  return await request(`${API_BASE_URL}/OA/contract/dealBaoXiao`, {
    method: 'POST',
    data: {
      id,
      agree,
      remark,
    },
  });
};

// 审核付款 - 使用string类型避免长整数精度丢失
export const dealPayApi = async (id: string, agree: boolean,remark:string,payObject:string) => {
  return await request(`${API_BASE_URL}/OA/contract/dealPay`, {
    method: 'POST',
    data: {
      id,
      agree,
      remark,
      payObject,
    },
  });
};

// 查询详情 - 通用详情查询接口
export const queryDetailApi = async (id: string, type: string) => {
  return await request(`${API_BASE_URL}/OA/query/contract/detail?id=${id}&type=${type}`, {
    method: 'POST',

  });
};

// 查询公告列表（首页“公告”模块）
// 说明：传当前登录用户的 id，POST 请求，返回公告列表
export const queryOaMessageListApi = async (id: string | number) => {
  // 使用 axios 的 params 传参，避免字符串拼接造成的编码或拦截器兼容问题
  // 同时保持 POST 并传递空 data，兼容某些后端对 POST 请求体的要求
  return await request(`${API_BASE_URL}/OA/query/queryOaMessageList`, {
    method: 'POST',
    params: { id: String(id) },
    data: {},
  });
};

// 查询消息通知列表（首页顶部“消息”入口）
// 说明：传当前登录用户的 id，POST 请求
// 返回结构：{ code, msg, data: { totalUnread, messageRespList: Array<...> } }
export const queryMessageApi = async (id: string | number) => {
  return await request(`${API_BASE_URL}/OA/query/queryMessage`, {
    method: 'POST',
    params: { id: String(id) },
    data: {},
  });
};

// 备用的mock数据函数（如果需要的话）
const getMockPendingData = () => {
  return {
    msg: "查询待处理信息成功 (Mock数据)",
    code: 0,
    data: {
      baoxiaos: [],
      pendingTotal: 8,
      contracts: [],
      pays: []
    }
  };
};

const getMockProcessedData = () => {
  return {
    msg: "查询已处理信息成功 (Mock数据)",
    code: 0,
    data: {
      baoxiaos: [],
      processedTotal: 8,
      contracts: [],
      pays: []
    }
  };
};

const getMockInitiatedData = () => {
  return {
    msg: "查询已发起数据成功 (Mock数据)",
    code: 0,
    data: {
      baoxiaos: [],
      contracts: [],
      pays: [],
      initiatedTotal: 8
    }
  };
};

const getMockReceivedData = () => {
  return {
    msg: "查询已收到数据成功 (Mock数据)",
    code: 0,
    data: {
      baoxiaos: [],
      receivedTotal: 0,
      contracts: [],
      pays: []
    }
  };
};